<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>文档</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <style>
        body{
          height: 100%;
          overflow: hidden;
        }
        .header {
            width: 90.7%;
            height: 25%;
            background-color: #40cccc;
            padding: 0.2rem 1.2rem;
            position: relative;
        }

        .header_top {
            width: 100%;
            height: 3rem;
        }

        .header_img {
            width: 10%;
            height: 80%;
        }

        .fl {
            float: left;
        }

        .fr {
            float: right;
        }

        .header_img img {
            width: 100%;
            height: 100%;
        }

        .header_nav {
            width: 100%;
            height: 4rem;
            color: #fff;
        }

        .pp {
            font-size: 2rem;
            line-height: 4rem;
        }

        .header_c {
            width: 100%;
            height: 2rem;
            color: #fff;
        }

        .header_c p {
            width: 20%;
            height: 1rem;
            text-align: center;
            font-size: 1.1rem;
        }

        .c {
            width: 100%;
            height: 1rem;
        }

        .lines_s {
            position: absolute;
            top: 60%;
            left: 22%;
            border-left: 1px solid #fff;
            width: 1px;
            height: 18px;
        }

        .header_f {
            width: 90%;
            height: 3.5rem;
            background-color: #fff;
            margin: 0.5rem auto;
            border-radius: 0.5rem;
            position: absolute;
            bottom:-20%;

            z-index: 999;
        }
        .one_top{
          width: 90%;
          height: 2rem;
          padding: 0.5rem 1rem;
        }
        .top_img{
          width: 10%;
          height: 100%;
          float: left;
        }
        .top_img img{
          width: 100%;
          height: 100%;
        }
        .one_top h3{
          float: left;
          margin-left: 0.5rem;

          line-height: 3rem;
        }
        .now{
          width: 50%;
          height: 3rem;
          background-color: #40cccc;
          border-radius: 1.5rem;
          color: #fff;
          line-height: 3rem;
          text-align: center;
          margin: 1rem auto 0rem;
        }
        .nows{
          width: 60%;
          height: 3rem;
          line-height: 3rem;
          text-align: center;
          margin: 0rem auto;
        }
        .main{
          width:100%;

          background-color: rgb(243, 243, 243, 0.5);

        }
        .top_imgs{
          float: right;
          width: 3%;
          height: 45%;
          margin-top: 1rem;
          }
          .top_imgs img{
            width: 100%;
            height: 100%;
          }
          .top{
            width: 93%;
            margin-top: 1rem;
            padding: 0.5rem 0.8rem;
          }

          .main_nav{
            width:93%;
            padding: 0.5rem 0.8rem;

            margin-top: 1.5rem;
            background-color: #fff;
              overflow: hidden;
          }
          .main_top{
            width: 100%;
            height: 4rem;
            line-height: 3.5rem;
          }
          .main_img{
            width: 6%;
            height:41%;
            margin-top: 0.5rem;
            margin-right: 0.5rem;
          }
          .main_img img{
            width: 100%;
            height: 100%;
          }
          .main_imgs{
            width: 32%;
            height: 55%;
            margin-left: 0.4rem;
            margin-top: 0.2rem;
          }
          .main_imgs img{
            width: 100%;
            height: 100%；
          }
          .no_left{
            width:60%;
            margin-top:21%;
            text-align:left;
            /*padding-left:1.2rem;*/
          outline: none;
          }

    </style>
</head>

<body>
    <div class="header" id="ss" style="display:none">
        <div class="header_top">
            <div class="header_img fl" onclick="openwin('setting')">
                <img src="../image/s1.png" alt="">
            </div>
            <div class="header_img fr">

            </div>
        </div>
        <div class="header_nav">
            <p class="fl pp" id="username">卡米儿</p>
            <div class="header_imgs fr">
                <img src="../image/a23.png" alt="" id="head_img" style="width:4rem;height:4rem;border-radius:2rem">
            </div>
        </div>
        <div class="header_c">
            <div class="c">
                <p class="fl" onclick="fx()">粉丝</p>
                <p class="fl" onclick="gz()">关注</p>
            </div>
            <div class="fl lines_s"></div>
            <div class="c" style="margin-top:0.5rem;">
                <p class="fl" onclick="fx()" id="fx">0</p>
                <p class="fl" onclick="gz()" id="gz">0</p>
            </div>
        </div>
    </div>
    <!-- 未登录状态下 -->
    <div class="header" id="sss" style="padding:0;width:82%;height:20%;margin:0 auto;display:block;background-color:#fff;border-bottom:0.3rem solid rgba(243,243,243,0.5)" onclick="login_at()">
      <div class="header_no">
        <div class="no_left fl">
          <button style="  font-weight: bold;font-size:1.5rem;  outline: none;">登录/注册</button>
          <p style="color:#ccc;font-size:1rem;margin-top:0.2rem;">登录获取更多优质服务</p>
        </div>
        <div class="no_right fr" style="margin-top:18%;">
          <img src="../image/45.png" alt="" style="width:4rem;height:4rem;border-radius:2rem">
        </div>
      </div>
      <!-- <div style="width:50%;height:20%;background-color:#CCCCCC;color:white;font-size:1.4rem;margin:0px auto;margin-top:20%;text-align:center;padding-top:1.2rem">立即登录</div> -->
    </div>
    <div class="main" id="baby">

      <div class="main_nav" id="nav">
        <div class="main_top" onclick="openwin('wo_wdyhj')">
            <div class="main_img fl">
              <img src="../image/aaa1.png">
            </div>
            <h4 class="fl">我的优惠券</h4>
            <div class="main_r fr">
              <p class="fl" id="yhj">0</p>
              <div class="main_imgs fl">
                <img src="../image/u32.png">
              </div>
            </div>
        </div>
        <div class="main_top" onclick="wdkc()">
            <div class="main_img fl">
              <img src="../image/u39.png">
            </div>
            <h4 class="fl">我的课程</h4>
            <div class="main_r fr">
              <p class="fl" id="kc">0</p>
              <div class="main_imgs fl">
                <img src="../image/u32.png">
              </div>
            </div>
        </div>
        <div class="main_top" onclick="wdsc()">
            <div class="main_img fl">
              <img src="../image/u43.png">
            </div>
            <h4 class="fl">我的收藏</h4>
            <div class="main_r fr">
              <p class="fl" id="sc">0</p>
              <div class="main_imgs fl">
                <img src="../image/u32.png">
              </div>
            </div>
        </div>
        <div class="main_top" onclick="dd()">
            <div class="main_img fl">
              <img src="../image/a47.png">
            </div>
            <h4 class="fl">订单管理</h4>
            <div class="main_r fr">
              <p class="fl" id="dd">0</p>
              <div class="main_imgs fl">
                <img src="../image/u32.png">
              </div>
            </div>
        </div>
        <div class="main_top" onclick="openwin('my_zy')">
            <div class="main_img fl">
              <img src="../image/aaa1.png">
            </div>
            <h4 class="fl">我的作业</h4>
            <div class="main_r fr">
              <p class="fl" id="zy">0</p>
              <div class="main_imgs fl">
                <img src="../image/u32.png">
              </div>
            </div>
        </div>
      </div>
    </div>
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.8.3.js"></script>
    <script type="text/javascript" src="../script/common.js"></script>
    <script>
    var resget = 0
    var userinfo = $api.getStorage('userinfo');
    apiready = function() {
      if(!userinfo){
        $("#ss").css({'display':'none'})
        $("#sss").css({'display':'block'})
      }else{
        $("#ss").css({'display':'block'})
        $("#sss").css({'display':'none'})
        get_user()
        get_some()//获取用户粉丝等参数
      }

      api.addEventListener({
    			name:'user_login',
    			extra:{
    					threshold:0
    			}
    	}, function(ret, err){
    					userinfo=$api.getStorage('userinfo');
              $("#ss").css({'display':'block'})
              $("#sss").css({'display':'none'})
    					get_user()//获取用户数据

              get_some()
    	});

      api.addEventListener({
    			name:'user_register',
    			extra:{
    					threshold:0
    			}
    	}, function(ret, err){
        $("#ss").css({'display':'block'})
        $("#sss").css({'display':'none'})
    					userinfo=$api.getStorage('userinfo');
    					get_user()//获取用户数据
get_some()

    	});

      api.addEventListener({
    			name:'user_out',
    			extra:{
    					threshold:0
    			}
    	}, function(ret, err){
        $("#ss").css({'display':'none'})
        $("#sss").css({'display':'block'})
    					userinfo=$api.getStorage('userinfo');
    					get_user()//获取用户数据
get_some()

    	});
      api.addEventListener({
          name:'up_user',
          extra:{
              threshold:0
          }
      }, function(ret, err){
              //userinfo=$api.getStorage('userinfo');
              get_user()//获取用户数据

      });
      api.addEventListener({
          name:'gz_user',
          extra:{
              threshold:0
          }
      }, function(ret, err){
              //userinfo=$api.getStorage('userinfo');
              get_some()//获取用户数据

      });

      api.addEventListener({
          name:'by_ok',
          extra:{
              threshold:0
          }
      }, function(ret, err){
              //userinfo=$api.getStorage('userinfo');
              get_some()//获取用户数据

      });

      api.addEventListener({
          name:'yy_ok',
          extra:{
              threshold:0
          }
      }, function(ret, err){
              //userinfo=$api.getStorage('userinfo');
              get_some()//获取用户数据

      });
      api.addEventListener({
          name:'add_baby',
          extra:{
              threshold:0
          }
      }, function(ret, err){
              //userinfo=$api.getStorage('userinfo');
              get_some()//获取用户数据

      });
      api.addEventListener({
          name:'sc',
          extra:{
              threshold:0
          }
      }, function(ret, err){
              //userinfo=$api.getStorage('userinfo');
              get_some()//获取用户数据

      });
    }

    function wdkc() {
      if(!userinfo){
        login_at()
        return false
      }
      api.openWin({
          name: 'mycur',
          url: './mycur.html'
      });
    }

    function wdsc() {
      if(!userinfo){
        login_at()
        return false
      }
      api.openWin({
          name: 'mycol',
          url: './mycol.html'
      });
    }
    function gz() {
      if(!userinfo){
        login_at()
        return false
      }
      api.openWin({
          name: 'myfollow',
          url: './myfollow.html'
      });
    }
    function fx() {
      if(!userinfo){
        login_at()
        return false
      }
      api.openWin({
          name: 'myfx',
          url: './myfx.html'
      });
    }

    function dd() {
      if(!userinfo){
        login_at()
        return false
      }
      api.openWin({
          name: 'myproorder',
          url: './myproorder.html'
      });
    }

    function addbb() {
      if(!userinfo){
        login_at()
        return false
      }
      api.openWin({
          name: 'addbb',
          url: './addbb.html'
      });
    }

    function baby() {
      if(!userinfo){
        login_at()
        return false
      }
      api.openWin({
          name: 'rjlb',
          url: './rjlb.html'
      });
    }



    function get_some() {
      var html =''
      var htmls =''
      $(".wbaby").remove()
      $(".hbaby").remove()
      api.ajax({
          url: SITE_URL+'user_api/user/user_some',
          method: 'post',
          data: {
              values: {
                  user_id: userinfo.id
              }
          }
      },function(ret, err){
          if (ret) {
            if(ret.error==200){
              if(ret.data.baby==1){//有宝宝
                html +='<div class="main_top hbaby" onclick="baby()">'
                    html +='<div class="main_img fl">'
                      html +='<img src="../image/aaa1.png">'
                    html +='</div>'
                    html +='<h4 class="fl">宝宝日记</h4>'
                    html +='<div class="main_r fr">'
                      html +='<p class="fl" id="zy">'+ret.data.rj+'</p>'
                      html +='<div class="main_imgs fl">'
                        html +='<img src="../image/u32.png">'
                      html +='</div>'
                    html +='</div>'
                html +='</div>'


                htmls +='<div class="header_f hbaby">'
                htmls +='<div class="one_top">'
                htmls +='<div class="top_img">'
                htmls +='<img src="'+ret.data.babys.head_img+'">'
                htmls +='</div>'
                htmls +='<h3 >'+ret.data.babys.name+'</h3>'
                htmls +='<p class="fr" style="line-height:3rem;">'+ret.data.babys.baby_time+'</p>'
                htmls +='</div>'
                htmls +='</div>'

                $(".wbaby").remove()
                $("#nav").prepend(html)
                $("#ss").append(htmls)
              }else {//无宝宝
                htmls +='<div class="header_f wbaby">'
                htmls +='<div class="one_top">'
                htmls +='<div class="top_img">'
                htmls +='<img src="../image/u28.png">'
                htmls +='</div>'
                htmls +='<h3 >宝宝名字</h3>'
                htmls +='<p class="fr" style="line-height:3rem;">宝宝生日</p>'
                htmls +='</div>'
                htmls +='</div>'


                html +='<div class="one_top top wbaby">'
                    html +='<h3>我家小宝日记</h3>'
                    html +='<div class="top_imgs">'
                      html +='<img src="../image/u32.png">'
                    html +='</div>'
                html +='</div>'
                html +='<div class="now wbaby" onclick="addbb()">'
                  html +='+添加第一天宝贝记'
                html +='</div>'
                html +='<div class="nows wbaby">'
                  html +='回看宝宝的成长超有意思哦！'
                html +='</div>'
                $(".hbaby").remove()
                  $("#ss").append(htmls)
                // $("#baby").prepend(html)
                $("#baby").prepend(html)
              }
              $("#gz").html(ret.data.gz)
              $("#fx").html(ret.data.fx)
              $("#sc").html(ret.data.sc)
              $("#kc").html(ret.data.kc)
              $("#dd").html(ret.data.dd)
              $("#yhj").html(ret.data.yhj)
              $("#zy").html(ret.data.zy)
            //$("#rj").html(ret.data.rj)
            }else{
              $("#gz").html('0')
              $("#fx").html('0')
              $("#sc").html('0')
              $("#kc").html('0')
              $("#dd").html('0')
              $("#yhj").html('0')
              $("#zy").html('0')
            //  $("#rj").html('0')
            }
              //alert( JSON.stringify( ret ) );
          } else {
            msgcode('请检查网络连接')
//              alert( JSON.stringify( err ) );
          }
      });

    }

    function get_user() {

      api.ajax({
          url: SITE_URL+'user_api/user/get_info',
          method: 'post',
          data: {
              values: {
                  user_id: userinfo.id
              }
          }
      },function(ret, err){
          if (ret) {
            if(ret.error==200){
              api.hideProgress();
              if(ret.data.nick_name){
                $("#username").html(ret.data.nick_name)
              }else{
                $("#username").html('宝宝早教')
              }
              if(ret.data.head_img){
                $("#head_img").attr('src',ret.data.head_img)
              }else{
                $("#head_img").attr('src','../image/a23.png')
              }

            }else{
              api.showProgress({
                  style: 'default',
                  animationType: 'fade',
                  title: '重新获取...',
                  text: '先喝杯茶...',
                  modal: false
              });
              if(resget>3){
                api.hideProgress();
                msgcode('获取个人信息失败')
                $("#username").html('宝宝早教')
                $("#head_img").attr('src','../image/a23.png')
              }else{
                setTimeout(function(){
                  get_user()
                },3000);
              }

            }
            //  alert( JSON.stringify( ret ) );
          } else {
            msgcode('请检查网络连接')
              //alert( JSON.stringify( err ) );
          }
      });
    }



    function openwin(data) {
      api.openWin({
          name: data,
          url: './'+data+'.html'
      });
    }
    </script>
</body>


</html>
